﻿using Newtonsoft.Json;
using SBlogCore.Application.Demo.Dto;
using SBlogCore.Application.Demo.IServices;
using SBlogCore.EventBus.CrossProcessEventBus.Attributes;

namespace SBlogCore.Application.Demo.Event.SubCross
{

    /// <summary>
    /// 
    /// </summary>
    public class SubCrossDemoEvent
    {
        private readonly IDemoService _service;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="service"></param>
        public SubCrossDemoEvent(IDemoService service)
        {
            _service = service;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="outPut"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        [CrossEventHandler("MyFirstCrossEventBus")]
        public async Task SubTest1(DemoOutPut outPut, string msg)
        {
            await Task.Delay(1000);
            Console.WriteLine($"第一个接收到消息：{JsonConvert.SerializeObject(outPut)}，{msg}{await _service.HelloDemo()}");
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="outPut"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        [CrossEventHandler("MyFirstCrossEventBus")]
        public async Task SubTest2(DemoOutPut outPut, string msg)
        {
            await Task.Delay(1000);
            Console.WriteLine($"第二个接收到消息：{JsonConvert.SerializeObject(outPut)}，{msg}{await _service.HelloDemo()}");
        }
    }
}
